package org.me.app.instructor;

import java.util.ArrayList;

import org.me.app.R;
import org.me.app.R.layout;
import org.me.bean.Announcement;
import org.me.bean.CourseSchedule;
import org.me.bean.InstructorData;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class TeachingCoursesActivity extends ListActivity {

	InstructorData instData = new InstructorData();
	ArrayList<CourseSchedule> teachingCourseList = new ArrayList<CourseSchedule>();
	ArrayList<Announcement> annList = new ArrayList<Announcement>();
	ArrayList<String> courseNameList = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		Bundle b = getIntent().getExtras();
		instData = b.getParcelable("InstructorData");
		teachingCourseList = (ArrayList<CourseSchedule>) instData
				.getTeachingCourseList();
		
		for (CourseSchedule cs : teachingCourseList) {
			courseNameList.add(cs.getCourseName());			
		}

		setListAdapter(new ArrayAdapter<CourseSchedule>(getApplicationContext(),
				R.layout.courseinfor, teachingCourseList));
		
		ListView lv = getListView();
		lv.setTextFilterEnabled(true);
		lv.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
								
				Intent i = new Intent(getApplicationContext(), 
						org.me.app.instructor.TabHostActivity.class);
				i.putParcelableArrayListExtra("AnnList", 
						(ArrayList<? extends Parcelable>) teachingCourseList.
						get(position).
						getAnnList());
				i.putExtra("Instructor", instData.getInstructor());
				i.putExtra("CourseScheduleId", teachingCourseList
						.get(position)
						.getCourseScheduleId());
				startActivity(i);
							
			}
		});

	}
}
